package org.fastsyncer.manager.listener.mysql.binlog.impl.parser;

import java.io.IOException;

import org.fastsyncer.manager.listener.mysql.binlog.BinlogEventV4Header;
import org.fastsyncer.manager.listener.mysql.binlog.BinlogParserContext;
import org.fastsyncer.manager.listener.mysql.binlog.impl.event.RotateEvent;
import org.fastsyncer.manager.listener.mysql.io.XInputStream;

public class RotateEventParser extends AbstractBinlogEventParser {

	public RotateEventParser() {
		super(RotateEvent.EVENT_TYPE);
	}

	public void parse(XInputStream is, BinlogEventV4Header header, BinlogParserContext context)
	throws IOException {
		final RotateEvent event = new RotateEvent(header);
		event.setBinlogFilename(context.getBinlogFileName());
		event.setBinlogPosition(is.readLong(8));
		event.setBinlogFileName(is.readFixedLengthString(is.available()));
		context.getEventListener().onEvents(event);
	}
}
